package org.processor;

import java.util.ArrayList;
import java.util.List;


public final class BeanClass extends TypeReference {

	private BeanClass superClass;
	private final Object originalObject;
	
	private List<BeanProperty> properties;
	private List<BeanProperty> resolvedProperties;
	
	public BeanClass(Object originalObject, String qualifiedName, String simpleName,
			String packageName, boolean nativeType, boolean defaultPackage) {
		super(qualifiedName, simpleName, packageName, nativeType, defaultPackage);
		this.originalObject = originalObject;
	}

	public BeanClass getSuperClass() {
		return superClass;
	}
	
	public List<BeanProperty> getProperties() {
		if (properties == null) {
			properties = new ArrayList<BeanProperty>();
		}
		return properties;
	}
	
	public List<BeanProperty> getResolvedProperties() {
		if (resolvedProperties == null) {
			if (getSuperClass() == null) {
				return getProperties();
			} else if (getProperties().size() == 0) {
				return getSuperClass().getResolvedProperties();
			} else {
				resolvedProperties = new ArrayList<BeanProperty>();
				resolvedProperties.addAll(getSuperClass().getResolvedProperties());
				resolvedProperties.addAll(getProperties());
			}
		}
		return resolvedProperties;
	}

	void setProperties(List<BeanProperty> properties) {
		this.properties = properties;
	}

	void setSuperClass(BeanClass superClass) {
		this.superClass = superClass;
	}
	
	Object getOriginalObject() {
		return originalObject;
	}
	
}
